package com.pirestupppai.widgets.dialog;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseDialog;
import com.pirestupppai.common.Constant;
import com.pirestupppai.utils.DownloadUtil;
import com.pirestupppai.utils.ImageLoadUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
 * 图片查看器
 *
 * @author: xiaoluo
 * @date: 2017-01-13 16:50
 */
public class ImageViewerDialog extends BaseDialog {

    @BindView(R.id.viewer_image)
    PhotoView viewerImage;

    private String mUrl;
    private List<String> mList = new ArrayList<>();

    public ImageViewerDialog(Context context, String url) {
        super(context, R.style.ViewerDialog);
        this.mUrl = url;
        mList.add(mUrl);
    }

    @Override
    protected int loadParentLayout() {
        return R.layout.dialog_img_viewer;
    }

    @Override
    protected boolean atBottom() {
        return false;
    }

    @Override
    protected void initViews() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) viewerImage.getLayoutParams();
        params.height = Constant.HEIGHT_OF_SCREEN;
        params.width = Constant.WIDTH_OF_SCREEN;
        viewerImage.setLayoutParams(params);

        ImageLoadUtil.getInstance().loadImage(mUrl, viewerImage);


    }

    @Override
    protected void initListeners() {
        viewerImage.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float x, float y) {
                dismiss();
            }
        });

        viewerImage.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DownloadUtil.downloadImage(mList);
                return true;
            }
        });
    }
}
